package tp.pr1;

public class Interpreter {

	public Instruction generateInstruction(java.lang.String line)
	{
		line=line.toUpperCase();
		String auxline[]=line.split(" ");
		
         if(auxline.length==1 &&
			(auxline[0].equals("HELP") || auxline[0].equals("MOVE") || auxline[0].equals("QUIT")))
			{  
				Instruction instruction = new Instruction(Action.valueOf(auxline[0]));
				return instruction;					
			}		
	 	 
		else if(auxline.length==2 &&
			 auxline[0].equals("TURN"))
			  {
			    if(auxline[1].equals("LEFT") || auxline[1].equals("RIGHT"))
			      {
			    	Instruction instruction = new Instruction(Action.valueOf(auxline[0]),Rotation.valueOf(auxline[1]));
			    	return instruction;
			      }
			     else
			      { 	
			        Instruction instruction = new Instruction(Action.valueOf(auxline[0]));
					return instruction;		
			      }
		      }
         
		else
		    {
			 Instruction instruction= new Instruction();
			 return instruction;
		    }
	}
	
	public java.lang.String interpreterHelp()
	{
		String LINE_SEPARATOR = System.getProperty("line.separator");
		return("The valid instructions for WALL·E are:"+LINE_SEPARATOR +
			" MOVE"+LINE_SEPARATOR +
			" TURN <LEFT | RIGHT>"+LINE_SEPARATOR +
			" HELP"+LINE_SEPARATOR +
			" QUIT");
	}	     
	
}
